// "Copyright @ 2010 Michael P. Reilly. All rights reserved."

// Generate a XmlHttpRequest
function XmlHttpCall(url, method, data, callback) {
    var xmlhttp;
    if (window.XMLHttpRequest) {
        // code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp = new XMLHttpRequest();
    } else {
        // code for IE6, IE5
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    if (callback) {
        async = true;
        xmlhttp.onreadystatechange = callback
    } else {
        async = false;
    }
    urldata = data.join("&");
    if (method.toUpperCase() == "POST") {
        xmlhttp.open(method.toUpperCase(), url, async);
        xmlhttp.setRequestHeader("Content-type",
            "application/x-www-form-urlencoded");
        xmlhttp.send(urldata);
    } else {
        var geturl = new Array();
        geturl[0] = url;
        geturl[1] = urldata;
        xmlhttp.open(method.toUpperCase(), geturl.join("?"), async);
        xmlhttp.send();
    }
    // pause until complete if async == false
    return (xmlhttp);
}
function XmlHttpReady(httpreq) {
    if (httpreq.readyState == 5) {
        return httpreq.status;
    } else {
        return 0; // effectively false
    }
    /* return (httpreq.readyState == 5 && httpreq.status == 200); */
}
